package com.wenxixuanwu.fruitstore.controller;

import com.wenxixuanwu.fruitstore.entity.User;
import com.wenxixuanwu.fruitstore.service.BackUserService;
import com.wenxixuanwu.fruitstore.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * @author :小凡凡
 * @version :1.0
 * @Project :fruitstore
 * @Date :2022/4/20
 */
@RestController
@RequestMapping("/backUsers")
public class BackUserController extends BaseController{

    @Autowired
    private BackUserService userService;

    @GetMapping("/findUserAll")
    public JsonResult<List<User>> findUserAll(){
        List<User> data = userService.findUserAll();
        return new JsonResult<>(OK,data);
    }

    @GetMapping("/getUserById/{id}")
    public JsonResult<User> getUserById(@PathVariable("id") Integer id){
        User data = userService.getUserById(id);
        return new JsonResult<User>(OK,data);
    }

    @PostMapping("/updateUserById")
    public JsonResult<Integer> updateUserById(@RequestBody User user){
        userService.updateUserById(user);
        return new JsonResult<Integer>(OK);
    }
}
